﻿using ipFoo.Models;

namespace ipFoo.Helpers
{
    internal static class Captcha
    {
        /// <summary>
        /// Takes the advanced feature model and validates that the captcha passed is accurate
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        internal static bool ValidRequest(AdvancedFeatureModel model)
        {
            var reval = new Recaptcha.RecaptchaValidator
            {
                Challenge = model.recaptcha_challenge_field,
                Response = model.recaptcha_response_field ?? string.Empty,
                PrivateKey = Settings.RecaptchaPrivateKey,
                RemoteIP = IpAddress.Get().IpAddress
            };

            return reval.Validate().IsValid;
        }
    }
}